/********************************************
 * 功能说明: User实体类对应的基础业务Repository
 * 模块名称:
 * 系统名称:
 * 软件版权: Frank
 * 系统版本: 1.0.0.1
 * 开发人员:
 * 开发时间: 2019-12-18 18:41:08
 * 审核人员:
 * 相关文档:
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.uaa.repository;

import com.spring.arch.uaa.model.User;
import com.spring.arch.uaa.model.QUser;
import com.spring.arch.uaa.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
import org.springframework.data.repository.Repository;

import java.util.Optional;
import java.util.UUID;

/**
 * User实体类对应的基础业务Repository
 *
 * @author Frank
 * @version 1.0.0.1
 * @since 2019-12-18 18:41:08
 */
@org.springframework.stereotype.Repository
public interface UserRepository extends Repository<User, UUID>,
        QuerydslPredicateExecutor<User>, QuerydslBinderCustomizer<QUser> {

    User save(User model);

//    User saveAndFlush(User model);

    Optional<User> findById(UUID id);

    Page<User> findAll(Pageable pageable);

    void deleteById(UUID id);

    void deleteAllByIdIn(Iterable<UUID> id);

    Optional<User> findByMobile(String username);

    Optional<User> findByAccount(String username);

    @Override
    default void customize(final QuerydslBindings bindings, final QUser quser){
        bindings.bind(quser.realName).first((path, value) -> quser.realName.containsIgnoreCase(value));
        bindings.bind(quser.mobile).first((path, value) -> quser.mobile.containsIgnoreCase(value));
    }
}

